package com.ingenieria;

import java.util.Random;
import java.util.TooManyListenersException;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.opengl.Visibility;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class IconCategory extends LinearLayout {

	private ImageView mView;
	private TextView txt;
	private int widthDimens, totalWidth, dimensCalculate;
	static Random random = new Random();
	
	public IconCategory(Context context, int twidth) {
		super(context);
		
		widthDimens = (twidth/3);
		totalWidth = widthDimens/10;
		dimensCalculate = widthDimens - totalWidth;
		float pixtodp = convertPixelesToDp(dimensCalculate, context);
		
		int width =Tools.pixelesFromDpi((int)pixtodp);
		int height = Tools.pixelesFromDpi(80);
		
		LayoutParams lparams = new LayoutParams(width, height);
		this.setOrientation(LinearLayout.VERTICAL);
		lparams.setMargins(0, 3, 0, 3);
		this.setLayoutParams(lparams);
		
		mView = new ImageView(context);
		mView.setId(0);
		LayoutParams lparm = new LayoutParams(Tools.pixelesFromDpi(55), Tools.pixelesFromDpi(55));
		lparm.gravity = Gravity.CENTER;
		mView.setLayoutParams(lparm);
		this.addView(mView);
		
		txt = new TextView(context);
		txt.setId(1);
		txt.setTextSize(11);
		txt.setLines(2);
		txt.setTextColor(Color.BLACK);
		txt.setGravity(Gravity.CENTER_HORIZONTAL);
		this.addView(txt);
	}
	
	public static float convertPixelesToDp(float px, Context context){
		Resources resource = context.getResources();
		DisplayMetrics metrics = resource.getDisplayMetrics();
		float dp = px/(metrics.densityDpi/160f);
		return dp;
	}
	
	@Override
	public void setOnClickListener(OnClickListener l) {
		mView.setOnClickListener(l);
	}

}
